import {findAllType, findPurchaseInfo} from '@/api/sales/salesPuStorage'
import pickerOptions from '@/utils/date';

export default {
    data() {
        return {
            pickerOptions,
            tableData: [],
            total: 0,
            searchParams: {currentPage: 1, pageSize: 10},
            dialogFormVisible: false,
            formData: {},
            options: []
        };
    },
    methods: {
        selectChange(brandList) {
            if (brandList.length == 1) {
                this.formData.id = brandList[0].id;
            }
            this.batchIds = brandList.map(item => item.id);
            console.log(this.batchIds)
        },
        async searchPage() {
            let response = await findPurchaseInfo(this.searchParams);
            this.tableData = response.data;
            this.total = response.total;
        },
        chooseTime() {
            this.searchParams.startTime = this.pickerOptions.startDate[0];
            this.searchParams.endTime = this.pickerOptions.startDate[1];
        },
        currentPageChange(currentIndex) {
            this.searchParams.currentPage = currentIndex;
            this.searchPage();
        },
        resetForm() {
            this.searchParams = {currentPage: 1, pageSize: 5}
            this.pickerOptions.startDate = '';
            this.searchPage()
        },
        lookPutStorage(id) {
            this.$router.push({
                path: `/putStorageDetails/${id}`,
            })
        },
        async findAllType() {
            this.options = await findAllType()
        },
        selectTable(row){
            return row.purchaseStatus === "录入完毕";
        },
        createExcel(goodId){
            window.location.href = "http://localhost:8088/putStorage/createBatchExcel/" + goodId;
        },
        createBatchExcel(){
            if (this.batchIds.length){
                window.location.href = "http://localhost:8088/putStorage/createBatchExcel/" + this.batchIds;
            }else {
                this.$notify.error({
                    title: '错误',
                    message: '选都没选下个寂寞?'
                });
            }
        }

    },
    created() {
        this.searchPage()
        this.findAllType()
    }
};
